var mongoose = require("mongoose"),
	Schema = mongoose.Schema;

//定义category对象模型
var categoryScheme = new Schema({
    title: {type:String, required:true},
	status: {type:Number, default:1},
	is_edit: {type:Boolean, default:true},
    created_date:{type:Date, default:Date.now},
    last_modified_date:{type:Date, default:Date.now},
    //一般插入为50， 默认分类为99
    order: {type:Number, default:50}
});

var tagScheme = new Schema({
    title: {type:String, required:true},
	status: {type:Number, default:1},
	color: {type:String, default:"#e11d21"},
	class_name: {type:String, default:"default"},
	is_edit: {type:Boolean, default:true},
    created_date:{type:Date, default:Date.now},
    last_modified_date:{type:Date, default:Date.now},
    //一般插入为50， 需要置顶的可大于50
    order: {type:Number, default:50}
});

//访问category对象模型
//mongoose会将我们传递的collection名小写化，
//同时如果小写化的名称后面没有字母――s,则会在其后面添加一s
var categoryModel = mongoose.model('Category', categoryScheme);
var tagModel = mongoose.model('Tag', tagScheme);

var todoScheme = new Schema({
    title: {type:String, required:true},
	content: String,
	category_id: {
		type: mongoose.Schema.ObjectId,
		//注意大小写
		ref: 'Category'
	},
	tag_ids: [{
		type: mongoose.Schema.ObjectId,
		ref: 'Tag'
	}],
	status: {type:Number, default:1},
	is_star: {type:Boolean, default:false},
	is_edit: {type:Boolean, default:true},
	is_done: {type:Boolean, default:false},
    todo_date:{type:Date, default:Date.now},
    created_date:{type:Date, default:Date.now},
    last_modified_date:{type:Date, default:Date.now},
    //一般插入为50， scuduled=40, expired=30, done=20
    order: {type:Number, default:50}
});

var todoModel = mongoose.model('Todo', todoScheme);

exports.categoryModel = categoryModel;
exports.tagModel = tagModel;
exports.todoModel = todoModel;
